class SongInfo {
  final String id;
  final String title;
  final String singer;
  final String quality;
  final String cover;
  final String lrcUrl;
  final String link;
  final String musicUrl;

  SongInfo({
    required this.id,
    required this.title,
    required this.singer,
    required this.quality,
    required this.cover,
    required this.lrcUrl,
    required this.link,
    required this.musicUrl,
  });

  factory SongInfo.fromJson(dynamic json) {
    final map = json is Map<String, dynamic>
        ? json
        : Map<String, dynamic>.from(json as Map<dynamic, dynamic>);

    return SongInfo(
      id: map['link']?.toString().split('/').last ?? map['n']?.toString() ?? '',
      title: map['title']?.toString() ?? '未知歌曲',
      singer: map['singer']?.toString() ?? '未知歌手',
      quality: map['quality']?.toString() ?? '',
      cover: map['cover']?.toString() ?? '',
      lrcUrl: map['lrc_url']?.toString() ?? '',
      link: map['link']?.toString() ?? '',
      musicUrl: map['music_url']?.toString() ?? '',
    );
  }
}
